package com.tz.mobilecloudpush;

import android.Manifest;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.tabs.TabLayout;
import com.migu.unionsdk.api.InitMonkeySdk;
import com.tbruyelle.rxpermissions2.RxPermissions;
import com.tz.mobilecloudpush.databinding.ActivityMainBinding;
import com.tz.mobilecloudpush.ui.main.SectionsPagerAdapter;

import cn.migu.tsg.mpush.MPush;
import cn.migu.tsg.mpush.base.OnResultHandler;
import io.reactivex.functions.Consumer;

public class MainActivity extends AppCompatActivity {

    private ActivityMainBinding binding;

    @SuppressLint("CheckResult")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //https://ecloud.10086.cn/home/product-introduction/push
        //https://push-cloud.migu.cn/#/appManage

        RxPermissions mRxPermission = new RxPermissions(this);
        mRxPermission.request(android.Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE)
                .subscribe(new Consumer<Boolean>() {
                    @Override
                    public void accept(Boolean aBoolean) throws Exception {
                        if (aBoolean) {
                        } else {
                        }
                    }
                });


        if (InitMonkeySdk.loadInit(this) &&
                InitMonkeySdk.loadPush(this)) {
            MPush.initPushWithCallBack(this, "appkey", new OnResultHandler() {
                @Override
                public void handleResult(int i, String s, String s1) {

                }
            });

        }

        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(this, getSupportFragmentManager());
        ViewPager viewPager = binding.viewPager;
        viewPager.setAdapter(sectionsPagerAdapter);
        TabLayout tabs = binding.tabs;
        tabs.setupWithViewPager(viewPager);
        FloatingActionButton fab = binding.fab;

        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
    }
}